﻿public class MinStack
{

    Stack<int> s = new Stack<int>();
    Stack<int> sm = new Stack<int>();
    int curMin = int.MaxValue;

    public MinStack()
    {

    }

    public void Push(int val)
    {
        s.Push(val);
        if (val <= curMin)
        {

            curMin = val;
           

        }

        sm.Push(curMin);
    }

    public void Pop()
    {
        
        s.Pop();
        sm.Pop();

        if(sm.Count == 0)
        {
            curMin=int.MaxValue;
        }
        else
        {
            curMin=sm.Peek();

        }
      

    }

    public int Top()
    {
        return s.Peek();
    }

    public int GetMin()
    {
        return sm.Peek();
    }
}

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack obj = new MinStack();
 * obj.Push(val);
 * obj.Pop();
 * int param_3 = obj.Top();
 * int param_4 = obj.GetMin();
 */
class Program155
{
    static void Main155(string[] args)
    {
        Console.WriteLine(int.MaxValue);
        MinStack obj = new MinStack();
       obj.Push(2147483646);
       obj.Push(2147483646);
       obj.Push(2147483647);
        Console.WriteLine(obj.Top());
        obj.Pop();
        Console.WriteLine(obj.GetMin());

        obj.Pop();
        Console.WriteLine(obj.GetMin());
        obj.Pop();
        obj.Push(2147483647);
        Console.WriteLine(obj.Top());
        Console.WriteLine(obj.GetMin());//7
    }
}